package com.tvunetworks.center.device.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.tvunetworks.center.common.util.MyUtil;
import com.tvunetworks.center.device.model.json.SetBitrateAndDelayParam;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: tvucc-device
 * @description: 封装R命令参数工具类
 * @author lebronchen
 * @create: 2019-03-15 13:56
 **/
@Slf4j
public class RCommandDataUtil {
    /**
     *
     * @param sourceId sourceId
     * @return String
     */
    public static String startStopLive(String sourceId){
        Map<String, String> map = new HashMap<>();
        map.put("TIdHex", sourceId);
        try {
            return MyUtil.MAPPER.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            log.error("msg:{},e:{}",e.getMessage(),e);
            log.error(e.toString(), e);
        }
        return null;
    }

    /**
     *
     * @param param param
     * @return String
     */
    public static String setBitrateAndDelay(SetBitrateAndDelayParam param){
        Map<String, Object> map = new HashMap<>();
        map.put("IdHex", param.getRid());
        map.put("BitRate", param.getBitrate());
        map.put("Delay", param.getDelay());
        try {
            return MyUtil.MAPPER.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            log.error("msg:{},e:{}",e.getMessage(),e);
            log.error(e.toString(), e);
        }
        return null;
    }

    /**
     *
     * @param args args
     */
    public static void main(String[] args) {
        String abc = RCommandDataUtil.startStopLive("abc");
        System.out.println(abc);
    }
}
